package db;

import com.zaxxer.hikari.HikariConfig;
import com.zaxxer.hikari.HikariDataSource;
import com.zaxxer.hikari.pool.HikariProxyConnection;
import oracle.jdbc.OracleConnection;

import java.sql.Date;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Timestamp;
import java.util.Arrays;

public class TimestampDemo {

    public static void main(String[] args) {
        HikariConfig config = DbConfigUtil.getHikariConfig();

        try (HikariDataSource dataSource = new HikariDataSource(config);
            HikariProxyConnection connection = (HikariProxyConnection)dataSource.getConnection()) {
            OracleConnection oracleConn = connection.unwrap(OracleConnection.class);
            oracle.jdbc.internal.OracleConnection var1 = oracleConn.physicalConnectionWithin();
            System.out.println("getTIMEZONETAB:" + var1.getTIMEZONETAB());
            String sql = "select * from date_demo";
            PreparedStatement preparedStatement = connection.prepareStatement(sql);
            ResultSet resultSet = preparedStatement.executeQuery();
            while(resultSet.next()) {
//                Object o1 = resultSet.getObject(1);
//                System.out.println(o1.getClass() + "|o1:" + o1);
//                //date
//                Object o2 = resultSet.getObject(2);
//                System.out.println(o2.getClass() + "|o2:" + o2);
                //timestamp
                Object o3 = resultSet.getObject(3);
                System.out.println(o3.getClass() + "|o3:" + o3);
                oracle.sql.TIMESTAMP o3T = (oracle.sql.TIMESTAMP)o3;
                Timestamp timestamp = o3T.timestampValue();
                System.out.println("o3ts:" + timestamp);
                Date date = o3T.dateValue();
                System.out.println("o3date:" + date);
                System.out.println("o3byte:" + Arrays.toString(o3T.getBytes()));
//                //timestamp with time zone
//                Object o4 = resultSet.getObject(4);
//                System.out.println(o4.getClass() + "|o4:" + o4);
//                //timestamp with local time zone
//                Object o5 = resultSet.getObject(5);
//                System.out.println(o5.getClass() + "|o5:" + o5);
            }
        } catch (SQLException e) {
            e.printStackTrace();
        }
    }
}
